package com.eeepay.eeepay_v2.util;

import android.content.Context;

import com.eeepay.eeepay_v2.R;
import com.eeepay.eeepay_v2.app.MyApplication;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Created by zw on 2016/4/15 0015.
 * 获取app的配置信息
 */
public class ConfigPorperties {

    private static ConfigPorperties configPorperties;

    private String teamId;
    private String appNo;
    private int versionCode;
    private String versionName; // 版本名称

    public static ConfigPorperties getInstance(){
        if(configPorperties == null && MyApplication.getInstance() != null){
            configPorperties = new ConfigPorperties(MyApplication.getInstance());
        }
        return configPorperties;
    }

    private ConfigPorperties(Context context){
        Properties properties = new Properties();
        try {
            InputStream inputStream = context.getAssets().open("config.properties");
            properties.load(inputStream);
            if (inputStream != null) {
                inputStream.close();
                inputStream = null;
            }

            teamId = context.getResources().getString(R.string.lib_team_id);
            appNo = context.getResources().getString(R.string.lib_app_no);
            versionCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
            versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public String getTeamId(){
        return teamId;
    }

    public String getAppNo() {
        return appNo;
    }

    public int getVersionCode() {
        return versionCode;
    }

    public void setVersionCode(int versionCode) {
        this.versionCode = versionCode;
    }

    public String getVersionName() {
        return versionName;
    }

    public void setVersionName(String versionName) {
        this.versionName = versionName;
    }
}
